package com.jplus.controller;

import com.jplus.VO.ResultVO;
import com.jplus.dao.UserDao;
import com.jplus.entity.Location;
import com.jplus.entity.User;
import com.jplus.handler.GlobalExceptionHandler;
import com.jplus.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class OrderController extends GlobalExceptionHandler {

    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "/create/order", method = RequestMethod.POST)
    public ResultVO createOrder(Location location, @RequestParam("sessionId") String sessionId) {
        return orderService.createOrder(location, sessionId);
    }

    @RequestMapping(value = "/accept/order", method = RequestMethod.POST)
    public ResultVO acceptOrder(String sessionId, String businessId) {
        return orderService.acceptOrder(sessionId, businessId);
    }

    @RequestMapping(value = "/cancel/order", method = RequestMethod.POST)
    public ResultVO cancelOrder(String sessionId, String businessId) {
        return orderService.cancelOrder(sessionId, businessId);
    }

    @RequestMapping(value = "/unaccepted/orders", method = RequestMethod.GET)
    public ResultVO getUnacceptedOrders(HttpServletRequest request) {
        return orderService.showUnacceptedOrders(request);
    }

    @RequestMapping(value = "/my/published/orders", method = RequestMethod.GET)
    public ResultVO getAllMyPublishedOrders(String sessionId) {
        return orderService.getAllMyPublishedOrders(sessionId);
    }

    @RequestMapping(value = "/my/got/orders", method = RequestMethod.GET)
    public ResultVO getAllMyGotOrders(String sessionId) {
        return orderService.getAllMyGotOrders(sessionId);
    }

    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    public ResultVO pay(String payChannel, String escrowTradeNo, String businessId) {
        return orderService.pay(payChannel, escrowTradeNo, businessId);
    }

    @RequestMapping(value = "/user/umbrella", method = RequestMethod.GET)
    public ResultVO getUmbrellaTypeArray() {
        return orderService.getUmbrellaTypeArray();
    }
}
